package daily.oct;

import java.util.Arrays;

public class lc611 {
    public int triangleNumber(int[] nums) {
        Arrays.sort(nums);//直接对原数组进行修改

        int count = 0;

        for (int i=0; i<nums.length-2; i++) {//i为头指针，因为要表示三个数，所以在倒数第三位时终止循环
            for (int j=i+1; j<nums.length-1; j++) {
                int sum = nums[i] + nums[j];
                for (int k=j+1; k<nums.length; k++) {
                    if (sum > nums[k]) {//两小边之和大于第三边
                        count++;
                    }else {
                        break;
                    }
                }
            }
        }

        return count;
    }

    public static void main(String[] args) {
        int[] nums1={2,2,3,4};
        int[] nums2={4,2,3,4};

        lc611 test=new lc611();
        System.out.println(test.triangleNumber(nums1));
        System.out.println(test.triangleNumber(nums2));

    }
}
